package itheima.edu.info.Exdents.Inface;

import java.util.Arrays;

public class carTest2 {
    public static void main(String[] args) {
        int [] a ={6,9,5,3,4,7,2,8,1};
        //6,1,5,3,4,7,2,8,9}
        //6,1,5,3,4,7,2,8,9}

         show(a,0,a.length-1);
        System.out.println(Arrays.toString(a));
    }

    private static void  show(int[] a, int left, int right) {
        //基准数的起始位置
        if (right<left){return;}
        int left0=left;
        int right0=right;
        //判断 left 和right的条件
        //循环基准数
        int num = a[left];

        while (right!=left) {

           /* while(arr[right] >= baseNumber && right > left){
                right--;
            }
            [2, 1, 5, 3, 4, 6, 7, 8, 9]
//        2，从左开始找比基准数大的
            while(arr[left] <= baseNumber && right > left){
                left++;
            }*/
            while ( a[right] >= num &&  right > left) {
                right--;
            }
            while ( a[left] <= num &&   right > left) {
                left++;
            }
            int s = a[right];
            a[right] = a[left];
            a[left] = s;
        }
            int i = a[left];
            a[left]=a[left0];
            a[left0]=i;
            show(a,left0,left-1);
            show(a,left+1,right0);
    }
}
